
//
//  UserListViewController.m
//  UI-豆瓣项目APP
//
//  Created by dllo on 15/9/8.
//  Copyright (c) 2015年 孙鹏. All rights reserved.
//

#import "UserListViewController.h"
#import "UserLandViewController.h"
#import "ActivityDetailController.h"
#import "MovieDetailControllerViewController.h"
@interface UserListViewController ()<UITableViewDataSource,UITableViewDelegate>

@end

@implementation UserListViewController

-(void)viewWillAppear:(BOOL)animated{
    
    NSString *isLogin = [[NSUserDefaults standardUserDefaults]objectForKey:@"isLogin"];
    
    if ([isLogin isEqualToString:@"1"]) {
        
        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"注销" style:UIBarButtonItemStylePlain target:self action:@selector(loginAction:)];
        
        
    }else{
        
        
        
        
    }
    
    
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    
    
    self.navigationItem.title = @"我的";
    self.userListVC = [[UITableView alloc]initWithFrame:[[UIScreen mainScreen]bounds] style:UITableViewStylePlain];
    self.userListVC.delegate = self;
    self.userListVC.dataSource = self;
    [self.view addSubview:self.userListVC];
    
    [self.userListVC registerClass:[UserListTableViewCell class] forCellReuseIdentifier:@"cell"];
    
    
   self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"登陆" style:UIBarButtonItemStylePlain target:self action:@selector(landAction:)];
    
    
    // Do any additional setup after loading the view.
}


- (void)loginAction:(UIBarButtonItem *)btn{
    
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"登陆" style:UIBarButtonItemStylePlain target:self action:@selector(landAction:)];
    
    NSString *isLogin = [[NSUserDefaults standardUserDefaults]objectForKey:@"isLogin"];
    [[NSUserDefaults standardUserDefaults]setObject:@"0" forKey:@"isLogin"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    NSLog(@"%@",isLogin);
   
}

-(void)landAction:(UIBarButtonItem *)btn
{
    
    UserLandViewController *userLandVC = [[UserLandViewController alloc]init];
    [self.navigationController pushViewController:userLandVC animated:YES];
    
    
    
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return 60;
    
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    
    return 3;
    
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdenfier =@"cell";
    UserListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdenfier];
    if (indexPath.row == 1) {
        cell.titleName.text = @"我的电影";
    }
    
    
    if (indexPath.row == 2) {
        
        cell.titleName.text = @"清除缓存";
        
    }
    
    return cell;
    
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    UserLandViewController *userLandVC = [[UserLandViewController alloc]init];
   
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    
    if ([[userDefaults objectForKey:@"isLogin"] isEqualToString: @"1"]&& indexPath.row == 0) {
        
        
        ActivityDetailController *actDVC = [[ActivityDetailController alloc]init];
        
        [self.navigationController pushViewController:actDVC animated:YES];
        
        
        
    }
    else if ([[userDefaults objectForKey:@"isLogin"] isEqualToString: @"0"]) {
        
        
         [self.navigationController pushViewController:userLandVC animated:YES];
        
        
    }else if ([[userDefaults objectForKey:@"isLogin"] isEqualToString: @"1"]&& indexPath.row == 1)
    {
        
        
        MovieDetailControllerViewController *movieDVC = [[MovieDetailControllerViewController alloc]init];
        
        [self.navigationController pushViewController:movieDVC animated:YES];
        
        
        
    }
    
    
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
